package com.zonski.jbots.engine.test;

import junit.framework.TestCase;

import com.zonski.jbots.engine.CollisionDetector;

public class CollisionDetectorTestCase extends TestCase
{
    public CollisionDetectorTestCase(String name)
    {
        super(name);
    }

    public void testHorizontalCrossIntersection()
    {
        int x = CollisionDetector.getXIntersection(0, -1, 0, 1, -1, 1, 0);
        TestCase.assertEquals(0, x);
    }

    public void testVerticalCrossIntersection()
    {
        int y = CollisionDetector.getYIntersection(-1, 0, 1, 0, 0, -1, 1);
        TestCase.assertEquals(0, y);
    }

    public void testOffsetHorizontalCrossIntersection()
    {
        int x = CollisionDetector.getXIntersection(2, -4, 2, -2, 1, 3, -3);
        TestCase.assertEquals(2, x);
    }

    public void testOffsetVerticalCrossIntersection()
    {
        int y = CollisionDetector.getYIntersection(-1, 5, 10, 5, 4, 4, 9);
        TestCase.assertEquals(5, y);
    }

    public void testNoHorizontalCrossIntersection()
    {
        int x = CollisionDetector.getXIntersection(2, -4, 2, -2, 4, 3, -3);
        TestCase.assertEquals(Integer.MIN_VALUE, x);
    }

    public void testNoVerticalCrossIntersection()
    {
        int y = CollisionDetector.getYIntersection(-1, 11, 10, 11, 4, 4, 9);
        TestCase.assertEquals(Integer.MIN_VALUE, y);
    }

    public void testDiagonalHorizontalIntersection()
    {
        int x = CollisionDetector.getXIntersection(-1, 1, 1, -1, -2, 2, 0);
        TestCase.assertEquals(0, x);
    }

    public void testDiagonalHorizontalIntersection2()
    {
        int x = CollisionDetector.getXIntersection(1, 1, -1, -1, -2, 2, 0);
        TestCase.assertEquals(0, x);
    }

    public void testOffsetDiagonalHorizontalIntersection()
    {
        int xoff = 12;
        int yoff = -3;
        int x = CollisionDetector.getXIntersection(1+xoff, 1+yoff, 
                -1+xoff, -1+yoff, 
                -2+xoff, 2+xoff, 0+yoff);
        TestCase.assertEquals(xoff, x);
    }

    public void testDiagonalVerticalIntersection()
    {
        int y = CollisionDetector.getYIntersection(-1, 1, 1, -1, 0, -2, 2);
        TestCase.assertEquals(0, y);
    }

    public void testDiagonalVerticalIntersection2()
    {
        int y = CollisionDetector.getYIntersection(1, 1, -1, -1, 0, -2, 2);
        TestCase.assertEquals(0, y);
    }

    public void testOffsetDiagonalVerticalIntersection()
    {
        int xoff = 12;
        int yoff = -3;
        int y = CollisionDetector.getYIntersection(1+xoff, 1+yoff, 
                -1+xoff, -1+yoff, 
                0+xoff, -2+yoff, 2+yoff);
        TestCase.assertEquals(yoff, y);
    }

    public void testHorizontalT()
    {
        int x = CollisionDetector.getXIntersection(100, 150, 100, 300, 50, 200, 300);
        TestCase.assertEquals(100, x);
        x = CollisionDetector.getXIntersection(100, 150, 100, 300, 50, 200, 150);
        TestCase.assertEquals(100, x);
    }

    public void testVerticalT()
    {
        int y = CollisionDetector.getYIntersection(0, 5, 10, 5, 10, 4, 6);
        TestCase.assertEquals(5, y);
        y = CollisionDetector.getYIntersection(0, 5, 10, 5, 0, 4, 6);
        TestCase.assertEquals(5, y);
    }

    public void testMiss()
    {
        int x = CollisionDetector.getXIntersection(15, 15, 25, 25, 20, 40, 5);
        assertEquals(Integer.MIN_VALUE, x);
    }
}
